package com.ssm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.ssm.entity.UserEntity;
import com.ssm.service.UserService;

import com.ssm.common.BaseController;

@RestController
@RequestMapping("user")
public class UserController extends BaseController{

	@Autowired
	private UserService userService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@ResponseBody
	public Object list(HttpServletRequest request){
	    Map<String, Object> params = new HashMap<String,Object>();
		int start = Integer.parseInt(request.getParameter("start"));
		int size = Integer.parseInt(request.getParameter("size"));
		return renderSuccess("返回信息",userService.queryByPageInfo(params, start, size));
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public Object info(HttpServletRequest request,@PathVariable("id") String id){
		return renderSuccess("返回信息",userService.queryById(id));
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public Object save(HttpServletRequest request,UserEntity user){
		userService.addEntrity(user);
		return renderSuccess();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public Object update(HttpServletRequest request,UserEntity user){
		userService.updateEntrity(user);
		return renderSuccess();
	}
	
	/**
	 * 删除
	 */
	 @ResponseBody
	@RequestMapping("/delete")
	public Object delete(HttpServletRequest request, String[] ids){
		userService.deleteEntrityBatch(Arrays.asList(ids));
		return renderSuccess();
	}
	
}
